﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SqlFileLayoutViewer {
    public partial class Magnifier : Form {
        public Magnifier() {
            InitializeComponent();
        }

        // The underlying bitmap we are magnifying
        public Bitmap pbm;

        // The point to focus on in that underlying bitmap
        public Point targetLocation;

        // The magnifier "grays out" the bands above and below the ones being
        // examined by overlaying this color:

        private SolidBrush dimArea = new SolidBrush(Color.FromArgb(185, 64, 64, 64));
        
        // Mess with the form a bit to make it borderless, yet have a shadow, and 
        // show without receiving focus or activating (like a tool tip):

        // Define the CS_DROPSHADOW constant
        private const int CS_DROPSHADOW = 0x00020000;

        // Override the CreateParams property
        protected override CreateParams CreateParams {
            get {
                CreateParams cp = base.CreateParams;
                cp.ClassStyle |= CS_DROPSHADOW;
                return cp;
            }
        }

        protected override bool ShowWithoutActivation {
            get { return true; }
        }

        private void MagPictureBox_Paint(object sender, PaintEventArgs e) {
            // Paint a section of the magnified image inside the magnifier, tracking
            // with the mouse and the image below
            if (pbm != null) {
                System.Drawing.Graphics g = e.Graphics;
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
                g.DrawImage(pbm,
                        new System.Drawing.Rectangle(0, 0, MagPictureBox.Width, MagPictureBox.Height),
                        this.targetLocation.X - 21,
                        this.targetLocation.Y - 21,
                        42,
                        42,
                        System.Drawing.GraphicsUnit.Pixel
                        );
                // Tint the area above and below the target row with
                // a darker overlay, to "pop" the one we are focused on

                g.FillRectangle(dimArea, 0, 0, MagPictureBox.Width, 27);
                g.FillRectangle(dimArea, 0, 55, MagPictureBox.Width, 28);

            }
        }
    }
}
